package com.itheima.behavior.controller.v1;

import com.itheima.behavior.service.LikeService;
import com.itheima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 点赞控制器
 * 提供图书、笔记、书评的点赞和取消点赞功能
 */
@RestController
@RequestMapping("/api/v1/like")
@Api(tags = "用户点赞相关接口")
public class LikeController {

    @Autowired
    private LikeService likeService;

    /**
     * 图书点赞
     * @param id 图书ID
     * @return 点赞结果
     */
    @PostMapping("/book/{id}")
    @ApiOperation("图书点赞")
    public ResponseResult likeBook(@ApiParam("图书ID") @PathVariable Integer id) {
        return likeService.likeBook(id);
    }

    /**
     * 取消图书点赞
     * @param id 图书ID
     * @return 取消点赞结果
     */
    @DeleteMapping("/book/{id}")
    @ApiOperation("取消图书点赞")
    public ResponseResult cancelLikeBook(@ApiParam("图书ID") @PathVariable Integer id) {
        return likeService.cancelLikeBook(id);
    }

    /**
     * 笔记点赞
     * @param id 笔记ID
     * @return 点赞结果
     */
    @PostMapping("/note/{id}")
    @ApiOperation("笔记点赞")
    public ResponseResult likeNote(@ApiParam("笔记ID") @PathVariable String id) {
        return likeService.likeNote(id);
    }

    /**
     * 取消笔记点赞
     * @param id 笔记ID
     * @return 取消点赞结果
     */
    @DeleteMapping("/note/{id}")
    @ApiOperation("取消笔记点赞")
    public ResponseResult cancelLikeNote(@ApiParam("笔记ID") @PathVariable String id) {
        return likeService.cancelLikeNote(id);
    }

    /**
     * 书评点赞
     * @param id 书评ID
     * @return 点赞结果
     */
    @PostMapping("/review/{id}")
    @ApiOperation("书评点赞")
    public ResponseResult likeReview(@ApiParam("书评ID") @PathVariable String id) {
        return likeService.likeReview(id);
    }

    /**
     * 取消书评点赞
     * @param id 书评ID
     * @return 取消点赞结果
     */
    @DeleteMapping("/review/{id}")
    @ApiOperation("取消书评点赞")
    public ResponseResult cancelLikeReview(@ApiParam("书评ID") @PathVariable String id) {
        return likeService.cancelLikeReview(id);
    }
}